import { io } from "socket.io-client";


// 1q2w3e4rQAZ@
export function createUserSocket(option) {
  const nsp = option.namespace || 'users';
  const id = option.id || '';
  if (!id) throw new Error('id is required');
  const socket = io(`http://192.168.163.36:3001/${nsp}/${id}`);
  socket.on('connect', () => {
    console.log('链接成功');
  })
  socket.on('disconnect', (msg) => {
    if (msg === 'io server disconnect') {
      console.log('disconnect:', '服务端强制断开socket')
    } else if (msg === 'io client disconnect') {
      console.log('disconnect:', '客户端使用socket.disconnect()手动断开socket')
    }
  })
  socket.on('reconnect_failed', () => {
    createUserSocket(option);
    console.log('socket 链接失败 正在尝试重连')
  })
  console.log(socket);
  return socket;

}









